<?php
class StringUtil {
	public static function changeFileName($fileName) {
		$time = time();
		$newName = $time . '_' . $fileName;
		return $newName;
	}
	
	private static function getMainContent($str, $arrPrefix) {
		$charsTrim = "\0\t\n\x0B\r .";
		
		$lenContent = strlen($str);
		foreach ($arrPrefix as $prefix) {
			$lenPrefix = strlen($prefix);
			$strLeft = substr($str, 0, $lenPrefix);
			$strRight = substr($str, $lenContent - $lenPrefix, $lenPrefix);
			if (strcmp($strLeft, $prefix) == 0) {
				return strtolower(trim(substr($str, $lenPrefix, $lenContent - $lenPrefix), $charsTrim));
			} else if (strcmp($strRight, $prefix) == 0) {
				return strtolower(trim(substr($str, 0, $lenContent - $lenPrefix), $charsTrim));
			}
		}
	}
	
	public static function getCityName($city) {
		$arrPrefix = array('city', 'tp');
		return StringUtil::getMainContent(strtolower($city), $arrPrefix);
	}
	
	public static function getDistrictName($district) {
		$arrPrefix = array('district', 'quận');
		return StringUtil::getMainContent(strtolower($district), $arrPrefix);
	}
	
	public static function getWardName($ward) {
		$arrPrefix = array('phường', 'p', 'th ward', 'st ward', 'rd ward', 'ward');
		return StringUtil::getMainContent(strtolower($ward), $arrPrefix);
	}
} 
?>